//
//  YWObserverCollectionCell.m
//  maintain
//
//  Created by kyo on 16/11/21.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWObserverCollectionCell.h"
#import "YWCommonTool.h"
#import "UIImageView+WebCache.h"
#import "YWMacro.h"
#import "UIColor+CustomColors.h"

#import "YWHandler.h"

@interface YWObserverCollectionCell()
@property (nonatomic, weak) UIImageView *imageView;
@property (nonatomic, weak) UILabel *nameLabel;
@end
@implementation YWObserverCollectionCell

- (instancetype)init{
    self = [super init];
    if (self) {
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.clipsToBounds = YES;
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [UIScreen mainScreen].scale;
        self.backgroundColor = [UIColor whiteColor];
        UIImageView *imageView = [[UIImageView alloc] init];
        //imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES;
        imageView.layer.cornerRadius = 4.0;
        
        [self.contentView addSubview:imageView];
        _imageView = imageView;
        
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:13];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor customTextGrayBlackColor];
        [self.contentView addSubview:label];
        _nameLabel = label;
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _imageView.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height-18);
    _nameLabel.frame = CGRectMake(3, CGRectGetMaxY(_imageView.frame), self.bounds.size.width-3*2, 18);
}

- (void)setHandler:(YWHandler *)handler{
    _handler = handler;
    _imageView.layer.borderWidth = 0;
    _imageView.layer.borderColor = [UIColor whiteColor].CGColor;
    NSString* downloadUrl = [YWCommonTool pictureDownloadUrl:handler.headIcon];
    [_imageView sd_setImageWithURL:[NSURL URLWithString:downloadUrl] placeholderImage:[UIImage imageNamed:@"profile_headimage"]];
    _nameLabel.text = handler.userName?:NSLocalizedString(@"unknowUser", nil);
}

- (void)setAddBtn:(BOOL)addBtn{
    _addBtn = addBtn;
    _imageView.layer.borderWidth = 0.7;
    _imageView.layer.borderColor = [UIColor customLineColor].CGColor;
    _imageView.image = [UIImage imageNamed:@"common_add"];
    _nameLabel.text = @"";
}

- (void)setDeleteBtn:(BOOL)deleteBtn{
    _deleteBtn = deleteBtn;
    _imageView.layer.borderWidth = 0.7;
    _imageView.layer.borderColor = [UIColor customLineColor].CGColor;
    _imageView.image = [UIImage imageNamed:@"common_delete"];
    _nameLabel.text = @"";
}

@end
